package module.edittroop.view.troopinfopanel
{
	import code.ui.SimpleToolTips;
	import code.utils.MaterialUtil;
	
	import com.darwin.darwinUI.containers.ContainerBase;
	import com.darwin.darwinUI.controls.Label;
	import com.darwin.darwinUI.controls.TextInput;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.general.TextFieldFactory;
	import com.darwin.darwinUI.manager.ToolTipManager;
	import com.darwin.darwinUI.manager.UIManager;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.profiler.showRedrawRegions;
	
	import module.edittroop.model.dataObj.SkillConfigObj;
	import module.main.view.ResourceConst;

	public class TroopInfoPanel extends ContainerBase
	{
		/**
		 *玩家英雄信息面板 
		 */		
		private var _troopInfoBg:Sprite;
		/**
		 *玩家头像框 
		 */		
		private var _troopHeadFream:Sprite;
		private var _skillUp:Sprite;
		private var _skillDown:Sprite;
		/**
		 *队伍名称背景 
		 */		
		private var _teamNameBg:Sprite;
		private var _teamName:Label = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
		private var _soliderInfoBg:Sprite;
		private var _uiComponent:UIComponent;
		/**
		 *兵种文本变量 
		 * 
		 */		
		private var _armsLabel:Label;
		private var _branchesLabel:Label;
		/**
		 *兵力文本 
		 */		
		private var _troopsLabel:Label;
		private var _troopsNumLable:Label;
		/**
		 *技能文本 
		 */		
		private var _skillLabel:Label;
		private var _skillNameLabel:Label;
		/**
		 *攻击力文本 
		 */
		private var _attackLable:Label;
		private var _attackNumLable:Label;
		/**
		 *防御力文本
		 */		
		private var _defenseLable:Label;
		private var _defenseNumLable:Label;
		/**
		 *英雄武力 
		 */		
		private var _heroForceLabel:Label;
		private var _heroForceNum:int;
		/**
		 * 英雄防御力
		 */		
		private var _heroDefenseLabel:Label;
		private var _heroDefenseNum:int;
		/**
		 *英雄幸运值 
		 */		
		private var _heroLuckLabel:Label;
		private var _heroLuckNum:int;
		/**
		 *英雄带兵上线文本 
		 */		
		private var _heroTroopLimitLabel:Label;
		private var _heroTroopLimitNum:int;
		/**
		 *射程文本 
		 */		
		private var _troopRangeLabel:Label;
		private var _troopRangeNum:int;
		/**
		 *攻击速度 
		 */		
		private var _attackSpeedLabel:Label;
		private var _attackSpeedNum:int;
		/**
		 *移动速度 
		 */		
		private var _moveSpeedLabel:Label;
		private var _moveSpeedNum:int;
		/**
		 *暴击率 
		 */		
		private var _critRateLabel:Label;
		private var _critRateNum:int;
		public function TroopInfoPanel()
		{
			_uiComponent = new UIComponent();
			addItem(_uiComponent);
			initView();
			initLable();
			setTroopInfoBg();
			setTeamName();
			setTroopHeadFream();
			setSoliderInfoBg();
		}
		private function initLable():void
		{
			/////////////兵种
			_armsLabel = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_branchesLabel = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_branchesLabel.text = "";
			_armsLabel.text = "兵种 : " + _branchesLabel.text;
			_armsLabel.x = 15;
			_armsLabel.y = (_soliderInfoBg.height  / 2 -_armsLabel .height) / 2;
			_soliderInfoBg.addChild(_armsLabel);
			
			/////////兵力
			_troopsLabel = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_troopsNumLable = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_troopsNumLable.text = "0";
			_troopsLabel.text = "兵力 : " + _troopsNumLable.text;
			_troopsLabel.x = 140;
			_troopsLabel.y = _armsLabel.y;
			_soliderInfoBg.addChild(_troopsLabel);
			
			///////兵种技能
			_skillLabel = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_skillNameLabel = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_skillNameLabel.text = "";
			_skillLabel.text = "兵种技能 : " + _skillNameLabel.text;
			_skillLabel.x = 260;
			_skillLabel.y = _armsLabel.y;
			_soliderInfoBg.addChild(_skillLabel);
			
			/////////攻击力
			_attackLable = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_attackNumLable = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_attackNumLable.text = "";
			_attackLable.text = "攻击 : " + _attackNumLable.text;
			_attackLable.x = _armsLabel.x;
			_attackLable.y = 61;
			_soliderInfoBg.addChild(_attackLable);
			
			///////部队射程
			_troopRangeLabel = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_troopRangeLabel.text = "部队射程 : "+ _troopRangeNum.toString();
			_troopRangeLabel.x = 140;
			_troopRangeLabel.y = 61;
			_soliderInfoBg.addChild(_troopRangeLabel);
			
			//////防御力
			_defenseLable = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_defenseNumLable = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_defenseNumLable.text = "";
			_defenseLable.text = "防御 : " + _defenseNumLable.text;
			_defenseLable.x = 260;
			_defenseLable.y = 61;
			_soliderInfoBg.addChild(_defenseLable);
			
			//////部队攻击速度
			_attackSpeedLabel = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_attackSpeedLabel.x = 15;
			_attackSpeedLabel.y = 100;
			_attackSpeedLabel.text = "攻击速度 : " + _attackSpeedNum.toString();
			_soliderInfoBg.addChild(_attackSpeedLabel);
			
			//////部队暴击率
			_critRateLabel = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_critRateLabel.x = 140;
			_critRateLabel.y = 100;
			_critRateLabel.text = "暴击率 : " + _critRateNum.toString();
			_soliderInfoBg.addChild(_critRateLabel);
			
			//////移动速度
			_moveSpeedLabel = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_moveSpeedLabel.x = 260;
			_moveSpeedLabel.y = 100;
			_moveSpeedLabel.text = "移动速度 : " + _moveSpeedNum.toString();
			_soliderInfoBg.addChild(_moveSpeedLabel);
			
			///////英雄武力
			_heroForceLabel = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_heroForceLabel.text = "武力 : " + _heroForceNum.toString();;
			_heroForceLabel.x = 115;
			_heroForceLabel.y = 35;
			_troopInfoBg.addChild(_heroForceLabel);
			
			//////英雄防御力
			_heroDefenseLabel = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_heroDefenseLabel.text = "防御 : " + _heroDefenseNum.toString();
			_heroDefenseLabel.x = _heroForceLabel.x;
			_heroDefenseLabel.y = _heroForceLabel.y + _heroForceLabel.height - 5;
			_troopInfoBg.addChild(_heroDefenseLabel);
			
			////////幸运值
			_heroLuckLabel = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_heroLuckLabel.text = "幸运 : " + _heroLuckNum.toString();
			_heroLuckLabel.x = 115;
			_heroLuckLabel.y = _heroDefenseLabel.y + _heroDefenseLabel.height - 7;
			_troopInfoBg.addChild(_heroLuckLabel);
			
			///////带兵上线
			_heroTroopLimitLabel = TextFieldFactory.getInstance().getLabel("building_tips_barrack_description");
			_heroTroopLimitLabel.text = "带兵上线 : " + _heroTroopLimitNum.toString();
			_heroTroopLimitLabel.x = 115;
			_heroTroopLimitLabel.y = _heroLuckLabel.y + _heroLuckLabel.height - 7;
			_troopInfoBg.addChild(_heroTroopLimitLabel);
		}
		private function initView():void
		{
			_troopInfoBg = MaterialUtil.getPreloadMaterial("EditTroop",ResourceConst.EDIT_TROOP_NAME_BACKGROUND) as Sprite;
			_troopHeadFream = MaterialUtil.getPreloadMaterial("EditTroop",ResourceConst.EDIT_TROOP_BIG_HEAD_FRAME) as Sprite;
			_teamNameBg = MaterialUtil.getPreloadMaterial("EditTroop",ResourceConst.EDIT_TROOP_NAME_LABLE) as Sprite;
			_soliderInfoBg = MaterialUtil.getPreloadMaterial("EditTroop",ResourceConst.EDIT_TROOP_SOLDIER_INFO_BG) as Sprite;
			_skillUp = MaterialUtil.getPreloadMaterial("EditTroop",ResourceConst.SKILL_ICON_UP) as Sprite;
			_skillDown = MaterialUtil.getPreloadMaterial("EditTroop",ResourceConst.SKILL_ICON_DOWN) as Sprite;
		}
		private function setTroopInfoBg():void
		{
			_uiComponent.addChild(_troopInfoBg);
			_troopInfoBg.y = _teamNameBg.height / 2;
			this.width = _troopInfoBg.width;
			this.height = _troopInfoBg.height + _teamNameBg.height / 2;
		}
		private function setTroopHeadFream():void
		{
			_troopHeadFream.x = _soliderInfoBg.x;
			_troopHeadFream.y = _teamNameBg.y + _teamNameBg.height;
			_skillUp.x = _troopHeadFream.width - _skillUp.width / 2;
			_skillUp.y = (_troopHeadFream.height / 2 - _skillUp.height) / 2 + 8;
			_skillUp.addEventListener(MouseEvent.MOUSE_MOVE,moveHandler);
			_skillDown.x = _skillUp.x;
			_skillDown.y =  (_troopHeadFream.height / 2 - _skillUp.height) / 2 + _troopHeadFream.height / 2 - 8; 
			_skillDown.addEventListener(MouseEvent.MOUSE_MOVE,moveHandler);
			_uiComponent.addChild(_troopHeadFream);
			_troopHeadFream.addChild(_skillUp);
			_troopHeadFream.addChild(_skillDown);
		}
		private function moveHandler(e:MouseEvent):void
		{
			switch(e.currentTarget)
			{
				case _skillUp:
					UIManager.getToolTipManager().showTips(SimpleToolTips,e.target,"噬脑",ToolTipManager.UP);
					break;
				case _skillDown:
					UIManager.getToolTipManager().showTips(SimpleToolTips,e.target,"噬魂",ToolTipManager.DOWN);
					break;
			}
		}
		private function setTeamName():void
		{
			_teamNameBg.x = _troopInfoBg.x + (_troopInfoBg.width - _teamNameBg.width) / 2;
			_teamNameBg.y = _troopInfoBg.y - _teamNameBg.height / 2 + 10;
			_uiComponent.addChild(_teamNameBg);
/*			_teamName.background = _teamNameBg;
			_teamName.x = _troopInfoBg.x + (_troopInfoBg.width - _teamNameBg.width) / 2;
			_teamName.y = _troopInfoBg.y - _teamNameBg.height / 2 + 10;
			_teamName.width = _teamNameBg.width;
			_teamName.height = _teamNameBg.height;*/
			_teamName.width = _teamNameBg.width;
			_teamName.height = _teamNameBg.height;
			_teamName.text = "正义队";
			_teamName.x = (_teamNameBg.width - _teamName.width) / 2;
			_teamName.y =  (_teamNameBg.height - _teamName.height) / 2;
			/*_teamName.border = false;*/
			_teamNameBg.addChild(_teamName)
		}
		private function setSoliderInfoBg():void
		{
			_soliderInfoBg.x = _troopInfoBg.x + (_troopInfoBg.width - _soliderInfoBg.width) / 2;
			_soliderInfoBg.y =5+  _troopHeadFream.y + _troopHeadFream.height + (_troopInfoBg.height - _troopHeadFream.y - _troopHeadFream.height - _soliderInfoBg.height) / 2;
			_uiComponent.addChild(_soliderInfoBg);
			_troopHeadFream.x = _soliderInfoBg.x;
		}
		public function changPanelInfo(obj:Object):void
		{
			//兵种
//			_branchesLabel.text = obj.armsName;
	//		_armsLabel.text = "兵种 : " + _branchesLabel.text;
			//兵力
			_troopsNumLable.text = obj.troopNum.toString();
			_troopsLabel.text = "兵力 : " + _troopsNumLable.text;
			//兵种技能
			//_skillNameLabel.text = obj.troopSkills;
			//_skillLabel.text = "兵种技能 : " + _skillNameLabel.text;
			//攻击力
			_attackNumLable.text = obj.troopAttack.toString();
			_attackLable.text = "攻击 : " + _attackNumLable.text;
			//防御力
			_defenseNumLable.text = obj.troopDefens.toString();
			_defenseLable.text = "防御 : " + _defenseNumLable.text;
			//名字
			_teamName.text = obj.troopName;
			
			//部队攻击速度
			_attackSpeedLabel.text = "攻击速度 : " + obj.attackSpeed;
			//暴击率
			_critRateLabel.text = "暴击率 : " + obj.critRate;
			
			//移动速度
			_moveSpeedLabel.text = "移动速度 ：" + obj.speed;
			//英雄武力
			_heroForceLabel.text = "武力 : " + obj.heroAttack;
/*			//英雄防御力
			_heroDefenseLabel.text = "防御 : "*/
			_heroLuckLabel.text = "幸运值 : "+ obj.lucky;
			
			_heroTroopLimitLabel.text = "带兵上线 : "
			
		}
	}
}